package com.mhd.get_coupon.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.Topic;

@Configuration
public class RabbitMQConfig {

    //1. 创建exchange - topic
    @Bean
    public TopicExchange getTopicExchange(){
        return new TopicExchange("coupon_info",true,false);
    }

    //2. 创建queue
    @Bean
    public Queue getQueue1(){
        return new Queue("couponToDB",true,false,false,null);
    }

    @Bean
    public Queue getQueue2(){
        return new Queue("couponToES",true,false,false,null);
    }

    //3. 绑定在一起
    @Bean
    public Binding getBinding1(TopicExchange topicExchange, Queue getQueue1){
        return BindingBuilder.bind(getQueue1).to(topicExchange).with("*.coupon.*");
    }
    @Bean
    public Binding getBinding2(TopicExchange topicExchange, Queue getQueue2){
        return BindingBuilder.bind(getQueue2).to(topicExchange).with("*.coupon.*");
    }


}